import aiohttp
import asyncio


async def fetch(session, url):
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.3'}
    print("开始下载： ", url)
    async with session.get(url, verify_ssl=False) as response:
        content = await response.content.read()
        file_name = url.rsplit('_')[-1]
        with open(file_name, 'wb') as fp:
            fp.write(content)
        print('下载完成: ', url)


async def main():
    async with aiohttp.ClientSession() as session:
        url_list = {
            'https://car2.autoimg.cn/cardfs/product/g25/M0B/99/EF/1024x0_1_q95_autohomecar__ChwFj19_uIWAQQgZABaZxAqb8BU552.jpg',
            'https://car3.autoimg.cn/cardfs/product/g25/M0A/5E/53/1024x0_1_q95_autohomecar__ChsEmF9zQUuAOt79ACT7Rgx018s791.jpg',
            'https://car2.autoimg.cn/cardfs/product/g26/M01/5B/D4/1024x0_1_q95_autohomecar__ChwFkF9zQc6AesUsACav7Ndb9c4212.jpg'
        }
        tasks = [
            asyncio.create_task(fetch(session, url)) for url in url_list
        ]
        await asyncio.wait(tasks)


if __name__ == '__main__':
    asyncio.run(main())
